using System;
using System.Windows.Data;

namespace Lib.Helper
{
    public class DecimalConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Object res =  0;
            if (value == null )
            {
                res =  0;
            }
            else
            {
                //if (value.ToString().Length >= 5)
                    res = string.Format(System.Globalization.CultureInfo.CurrentUICulture, "{0:N}", value);
                //else
                //    res = value;    
            }

            return res;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;// return Decimal.Parse(value.ToString());
        }
    }


    public class DecimalConverter4Digit : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Object res = 0;
            if (value == null)
            {
                res = 0;
            }
            else
            {
                //if (value.ToString().Length >= 5)
                res = string.Format(System.Globalization.CultureInfo.CurrentUICulture, "{0:0.0000}", value);
                //else
                //    res = value;    
            }

            return res;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;// return Decimal.Parse(value.ToString());
        }
    }
}
